<?php
/**
 * @Author: gan
 * @Description:
 * @File:  CloudPrintStaticFactory
 * @Version: 1.0.0
 * @Date: 2022/5/24 9:01 上午
 */
declare(strict_types=1);

namespace RX\Component\CloudPrint;

use Psr\SimpleCache\CacheInterface;
use RX\Component\CloudPrint\Impl\FeiEYunImpl;
use RX\Component\CloudPrint\Impl\YiLianYunImpl;
use RX\Enums\CommonEnum;
use RX\Exception\BizException;

class CloudPrintStaticFactory
{
    /**
     * @param string $type
     * @param array $config
     * @param CacheInterface $cache
     * @return FeiEYunImpl|YiLianYunImpl
     * @throws BizException
     */
    public static function factory(string $type, array $config, ?CacheInterface $cache)
    {
        switch ($type) {
            case CloudPrintType::YI_LIAN_YUN:
                return new YiLianYunImpl($config, $cache);
            case CloudPrintType::FEI_E_YUN:
                return new FeiEYunImpl($config);
            default:
                throw new BizException(CommonEnum::class, CommonEnum::INVALID_PARAMS);
        }
    }
}
